<template>
  <tableDrawer
    ref="tableDrawerPack"
    loadForce
    :propShowChildCheckbox="false"
    refName="tableDrawerPack"
    viewKey="base_pack_templet_select"
    :queryWrapper="cpPackQueryWrapper"
    :matrPackTempletPropUserParam="{deptId: deptId}"
    title="请选择跟台模板"
    subtitle="所属供应商、所属科室"
    :propBeforeConfirm="tableDrawerPackBeforeConfirm"
    :widthPx="-1"
    :heightPx="-1"
    :widthPer="80"
  >
    <template #contentTop>
      <customForm :data="formPack" :rules="formPackRules" ref="formPack">
        <template #content>
          <customFormItem label="批次" name="lot" :parent="_self" :form="formPack" />
          <customFormItem label="效期" name="expDate" :parent="_self" :form="formPack" :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="生产日期" name="mfgDate" :parent="_self" :form="formPack" :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="灭菌日期" name="sterilizationDate" :parent="_self" :form="formPack" :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="灭菌效期" name="sterilizationIndate" :parent="_self" :form="formPack" :type="constCommon.formItemType.datePicker.name"/>
        </template>
      </customForm>
    </template>
  </tableDrawer>
</template>

<script>
export default {
  desc: '弹框表格选择控件-跟台包',
  name: 'tableDrawerPackOperBag',
  components: {
  },
  props: {
    /**
     * @Description：供应商
     */
    supplierId: {
      type: String,
      default: () => null,
    },
    /**
     * @Description：科室
     */
    deptId: {
      type: String,
      default: () => null,
    }
  },
  created() {
  },
  data() {
    return {
      formPack: {},

      // 包输入规则
      formPackRules: {
        lot: [{ required: true, message: '请输入', trigger: 'blur' }],
        expDate: [{ required: true, message: '请选择', trigger: 'blur' }],
        mfgDate: [{ required: true, message: '请选择', trigger: 'blur' }],
        sterilizationDate: [{ required: true, message: '请选择', trigger: 'blur' }],
        sterilizationIndate: [{ required: true, message: '请选择', trigger: 'blur' }],
      }

    }
  },
  methods: {
    // 显示
    inst() {
      return this.$refs.tableDrawerPack
    },
    // 显示
    show() {
      // this.formPack = {}
      this.inst().show(null, true)
    },

    // 隐藏
    hide() {
      this.inst().hide()
    },
    // 包弹框确认前
    tableDrawerPackBeforeConfirm(){
      this.$refs.formPack.validate().then((result) => {
        if (result && result == true) {
          let data = this.inst().getData()
          if (data == null || data.length == 0) {
            this.utilMessage.warning('请选择要添加的跟台包')
            return
          }
          this.$emit('confirm', data, this.formPack)
        }
      })
      return false
    }
  },
  watch: {
  },
  computed: {
    // 跟台包查询条件
    cpPackQueryWrapper() {
      let wrapper = global.$newWrapper()
      wrapper.eq('packType', this.constCommon.dictType.tempTypeOperBag)
      wrapper.eq('supplierId', this.supplierId)
      return wrapper
    }
  }
}
</script>
